from welcome . gui import welcome_gui

class frame_fake :
    _deleted_count = 0
    def __init__ ( self , master ) :
        self . _master = master
        self . _packed = False
        self . _destroyed = False
    def __del__ ( self ) :
        frame_fake . _deleted_count += 1
        
class label_fake :
    def __init__ ( self , master , text ) :
        self . _master = master
        self . _text = text
        self . _packed = False

class image_fake :
    _deleted_count = 0
    def __init__ ( self , master , data ) :
        self . _master = master
        self . _data = data
        self . _packed = False
    def __del__ ( self ) :
        image_fake . _deleted_count += 1

class mediator_fake :
    def __init__ ( self ) :
        self . _welcome_gui = None
        self . _application_window = None
        self . _widgets = [ ]
        self . _welcome_title = None
        self . _welcome_header = None
        self . _welcome_footing = None
        self . _resources = { }
    def application_window_request ( self ) :
        self . _welcome_gui . application_window_reply ( self . _application_window )
    def gui_create_frame_request ( self , master ) :
        frame = frame_fake ( master )
        self . _widgets += [ frame ]
        self . _welcome_gui . gui_create_frame_reply ( frame )
    def gui_pack ( self , widget , padx = None , pady = None , side = None , fill = None ) :
        widget . _packed = True
    def gui_create_label_request ( self , master , text ) :
        label = label_fake ( master , text )
        self . _widgets += [ label ]
        self . _welcome_gui . gui_create_label_reply ( label )
    def localization_welcome_title ( self ) :
        return self . _welcome_title
    def gui_side_top ( self ) :
        pass
    def localization_welcome_header ( self ) :
        return self . _welcome_header
    def localization_welcome_footing ( self ) :
        return self . _welcome_footing
    def get_resource ( self , resource ) :
        if resource in self . _resources :
            return self . _resources [ resource ]
        else :
            return None
    def gui_create_image_request ( self , master , data ) :
        image = image_fake ( master , data )
        self . _widgets += [ image ]
        self . _welcome_gui . gui_create_image_reply ( image )
    def gui_destroy_frame ( self , frame ) :
        frame . _destroyed = True

class welcome_gui_tests :
    'welcome_gui'
    def __init__ ( self , test ) :
        frame_fake . _deleted_count = 0
        image_fake . _deleted_count = 0
        self . _test = test
        self . _mediator = mediator_fake ( )
        self . _welcome_gui = welcome_gui ( self . _mediator )
        self . _mediator . _welcome_gui = self . _welcome_gui
        
    #
    # show_welcome
    #
        
    def test_show_welcome_create_frame ( self ) :
        self . _mediator . _application_window = 'my window'
        self . _welcome_gui . show_welcome ( )
        frame = self . _mediator . _widgets [ 0 ]
        self . _test . assume_equal ( frame . _master , 'my window' )
        self . _test . assume_true ( frame . _packed )
    def test_show_welcome_title_label ( self ) :
        self . _mediator . _welcome_title = 'my title'
        self . _welcome_gui . show_welcome ( )
        frame = self . _mediator . _widgets [ 0 ]
        title = self . _mediator . _widgets [ 1 ]
        self . _test . assume_equal ( title . _master , frame )
        self . _test . assume_equal ( title . _text , 'my title' )
        self . _test . assume_true ( title . _packed )
    def test_show_welcome_header_label ( self ) :
        self . _mediator . _welcome_header = 'my header'
        self . _welcome_gui . show_welcome ( )
        frame = self . _mediator . _widgets [ 0 ]
        header = self . _mediator . _widgets [ 2 ]
        self . _test . assume_equal ( header . _master , frame )
        self . _test . assume_equal ( header . _text , 'my header' )
        self . _test . assume_true ( header . _packed )
    def test_show_welcome_image ( self ) :
        self . _mediator . _resources [ welcome_gui . _welcome_image ] = 'my image data'
        self . _welcome_gui . show_welcome ( )
        frame = self . _mediator . _widgets [ 0 ]
        image = self . _mediator . _widgets [ 3 ]
        self . _test . assume_equal ( image . _master , frame )
        self . _test . assume_equal ( image . _data , 'my image data' )
        self . _test . assume_true ( image . _packed )
    def test_show_welcome_image_persistance ( self ) :
        self . _welcome_gui . show_welcome ( )
        self . _mediator . _widgets = [ ]
        self . _test . assume_equal ( image_fake . _deleted_count , 0 )
    def test_show_welcome_footing_label ( self ) :
        self . _mediator . _welcome_footing = 'my footing'
        self . _welcome_gui . show_welcome ( )
        frame = self . _mediator . _widgets [ 0 ]
        footing = self . _mediator . _widgets [ 4 ]
        self . _test . assume_equal ( footing . _master , frame )
        self . _test . assume_equal ( footing . _text , 'my footing' )
        self . _test . assume_true ( footing . _packed )
    def test_show_welcome_frame_not_destroyed ( self ) :
        self . _welcome_gui . show_welcome ( )
        frame = self . _mediator . _widgets [ 0 ]
        self . _test . assume_false ( frame . _destroyed )
        
    #
    # hide_welcome
    #
        
    def test_hide_welcome_destroy_frame ( self ) :
        self . _welcome_gui . show_welcome ( )
        self . _welcome_gui . hide_welcome ( )
        frame = self . _mediator . _widgets [ 0 ]
        self . _test . assume_true ( frame . _destroyed )
    def test_hide_welcome_image_destruction ( self ) :
        self . _welcome_gui . show_welcome ( )
        self . _welcome_gui . hide_welcome ( )
        self . _mediator . _widgets = [ ]
        self . _test . assume_equal ( image_fake . _deleted_count , 1 )
    def test_hide_welcome_frame_destruction ( self ) :
        self . _welcome_gui . show_welcome ( )
        self . _welcome_gui . hide_welcome ( )
        self . _mediator . _widgets = [ ]
        self . _test . assume_equal ( frame_fake . _deleted_count , 1 )
        